class_name PlayerAirState
extends GameplayStateMachine

@onready var player: Player = $"../../"


func _on_setup() -> void:
	add_transition("AnyState", GameplaySimpleTransition.new("PlayerUpState", func(): return player.velocity.y < 0, func(): pass))
	add_transition("AnyState", GameplaySimpleTransition.new("PlayerDownState", func(): return player.velocity.y >= 0, func(): pass))


func _on_update(delta: float) -> void:
	var max_movement_speed = player.player_stats.walk_speed if player.player_input_handler.walk_input else player.player_stats.run_speed
	
	player.velocity.x += player.player_input_handler.movement_input * player.player_stats.movement_speed_agument * delta
	player.velocity.x = clampf(player.velocity.x, -max_movement_speed, max_movement_speed)
	
	if player.player_input_handler.movement_input * player.face_direction < 0:
		player.flip()
